package com.zhdl.network.common_server;

import cn.hutool.core.util.HexUtil;
import com.project.command.faq.queues.data.ControlInstructionPerformData;
import com.project.command.instruction.service.InstructionSendService;
import com.project.command.instruction.strategy.abs.AbsAfterControlCommand;
import com.project.command.instruction.strategy.process.data.AfterStrategyParam;
import com.zhdl.network.common_server.dto.ServerTcpDto;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 手操器默认收到数据处理策略
 *
 * @Author: zhangyy
 * @Email: zhang10092009@hotmail.com
 * @Date: 2023/4/18 10:58:35
 * @Version: v1.0
 * @Modified: 手操器默认收到数据处理策略
 * @Description: 手操器默认收到数据处理策略
 */
@Slf4j
@Service(CommonTcpServerAfter.COMMON_TCP_SERVER_AFTER_SERVICE)
public class CommonTcpServerAfter extends AbsAfterControlCommand<ServerTcpDto, ByteBuf> {
    public static final String COMMON_TCP_SERVER_AFTER_SERVICE = "commonTcpServerAfter";

    @Resource
    private InstructionSendService instructionSendService;

    @Override
    public boolean afterResultJudge(AfterStrategyParam resp) {

        log.info("CommonTcpServerAfter-->{}", resp);

        ControlInstructionPerformData data = new ControlInstructionPerformData();
        data.setInstruction(HexUtil.decodeHex(resp.getInstruction()));
        data.setPortKey(resp.getPortKey());
        data.setProtocols(resp.getProtocols());
        data.setAfterInstructionName(resp.getInstructionName());
        data.setDataBit(1);
        data.setChain("010101");
        instructionSendService.sendToClient(data);

        return true;
    }

}
